/**
 * @author: zzj
 * @date: 2021/12/21
 */
import {reactive} from 'vue';
import Crud from './f-crud';
import Btn from './f-crud/module/btn';
import Dialog from './f-crud/module/dialog';
import Form from './f-crud/module/form';
import Page from './f-crud/module/page';
import Search from './f-crud/module/search';
import Table from './f-crud/module/table';

const plugin = Object.create(null);
plugin.install = function (app, options) {
  if (options) {
    for (let key in options) {
      if (options.hasOwnProperty(key))
        app.config.globalProperties['$' + key] = options[key];
    }
  }
  app.component(Crud.name, Crud);
  app.component(Btn.name, Btn);
  app.component(Dialog.name, Dialog);
  app.component(Form.name, Form);
  app.component(Page.name, Page);
  app.component(Search.name, Search);
  app.component(Table.name, Table);
};
export default plugin;

/**
 *
 * @param config {CrudConfig<any>}
 * @returns {CrudConfig<any>}
 */
export function defineCrudConfig(config) {
  return reactive(config);
}
